|
|
|
|
|
|
|
In this example, the second line of code is able to access information in a control on frmApplication, even though that form is not visible on the screen. The Hide method leaves a form in memory. |
|
|
|
|
|
|
|
|
If you are finished with a form and the information contained on it, you can remove it from both the screen and memory by using the Unload statement. The Unload statement uses basically the same syntax as the Load statement, as shown here: |
|
|
|
|
| |
|
|
|
|
If you are using the Unload statement from within the form you are removing, you can use the keyword Me to specify the form. By using this approach, you can prevent errors if you later rename your form. In this case, the statement would be the following: |
|
|
|
|
|
 |
|
 |
|
|
Using Load to Enhance Program Performance |
|
|
|
 |
|
 |
|
|
Because the Show method automatically loads a form into memory, you typically do not need to use the Load statement in your program at all. However, some forms with a very large number of controls display slowly when they are shown. One way around this problem is to load the form into memory by using the Load statement when the program begins to run. With the form already in memory, subsequent Hide and Show methods appear to perform much more quickly. If you use this trick, be careful of two things. First, don't forget to unload the form at the end of your program. Second, be aware of possible memory limitations. If you load too many forms in memory at once, you might see a decline in the overall performance of your program. |
|
|
|
 |
|
 |
|
|
Loading forms into memory does increase the amount of time required for your program to start, but you will save time whenever the form is shown. If you show a form only once during the program, no net time savings is gained by loading it at the beginning. However, if the form is shown more than once, usually an overall time savings is experienced. Also, users are typically more tolerant of time delays when a program loads (especially if they're busy looking at a splash screen) than later when they are performing a task. |
|
|
|
|
|
|
|
|
This chapter introduced you to the world of forms and controls. You began to see how to use forms and controls as the basic building blocks of user interface design. You learned how to manage the appearance of forms and controls by manipulating their properties, both at designtime and runtime. The basic concepts discussed here will carry over into the upcoming discussions of many of the controls that are available for you to use in designing your Visual Basic applications. |
|
|
|
|
|
|
|
|
Learn more about the standard controls by reading Chapter 4, "Using Visual Basic's Default Controls." |
|
|
|
|
|